package cn.tianyigps.tianyigpsapiv2.dao;

import cn.tianyigps.tianyigpspublic.bean.EquipmentHistory;
import cn.tianyigps.tianyigpspublic.bean.EquipmentLastData;
import cn.tianyigps.tianyigpspublic.bean.EquipmentModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * @Author: LiuHao
 * @Descirption:
 * @Date: 2019/4/26_16:03
 */
@Repository
public class EquipmentHistoryDao extends BaseDao<EquipmentHistory>  {


    @Autowired
    private MongoTemplate mongoTemplate;

    public List<EquipmentHistory> findByDateTimeAndEquipmentId(Date start, Date end, String equipmentId) {
        Query query = new Query();
        query.addCriteria(Criteria.where("equipmentId").is(equipmentId));
        query.addCriteria(Criteria.where("signalTime").gte(start).lte(end));
        query.with(new Sort(Sort.Direction.ASC, "signalTime"));
        List<EquipmentHistory> list = mongoTemplate.find(query,EquipmentHistory.class);
        return list;
    }
}
